feat: support external browser + page in puppeteer options#201677
feat: support external browser + page in puppeteer options#201677Adi1231234 wants to merge 8 commits intowwebjs:mainfrom
Conversation
allow passing a pre-existing `browser` and `page` via `options.puppeteer` so the Client can work with a browser you already control. when both are provided, the Client skips puppeteer.launch() and uses them directly. also uses browser.process() in destroy/logout to decide cleanup: close() for launched browsers, disconnect() for connected ones.
b654043 to
ff2e280
Compare
|
@sofi-ans Can you check this PR? 🙏 |
LGTM. One suggestion: if only browser is passed without page, you could create a new page instead of falling through to a new browser: if (puppeteerOpts.browser) {
browser = puppeteerOpts.browser;
page = puppeteerOpts.page || await browser.newPage();
}This matches what the browserWSEndpoint path already does. |
create a new page via browser.newPage() when only browser is provided, matching the existing browserWSEndpoint behavior.
Done 🙏 |
Looks good, approved |
|
Awesome to see someone finally opened a PR for this, I’ve literally been relying on patches for this exact issue |
Adds support for passing a pre-existing
browserandpageviaoptions.puppeteer, so the Client can work with a browser you already control (e.g. Electron's built-in Chromium, or a shared browser pool).When both
browserandpageare provided, the Client skipspuppeteer.launch()/puppeteer.connect()and uses them directly. Existing behavior is unchanged when these options are not set.What changed
initialize()- newifbranch before the existingbrowserWSEndpointcheck:destroy()/logout()- usebrowser.process()to decide cleanup:process() !== null(we launched it) ->browser.close()as beforeprocess() === null(external browser) ->browser.disconnect()onlyWithout this,
browser.close()sends CDPBrowser.closewhich kills the entire external browser, not just this client's session.disconnect()only closes the WebSocket, leaving the browser running.This is the same pattern puppeteer uses internally in
Symbol.dispose.Example